package com.hspedu.newData.dmsxl.树.二叉树的遍历.递归;

import com.hspedu.newData.dmsxl.ds.TreeNode;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-04-29 
 * @Version: 1.0
 */

public class LC114二叉树展开为链表 {

    // todo
    public void flatten(TreeNode root) {

        while(root != null){
            if (root.left == null){
                root = root.right;
            }else {
                TreeNode pre = root.left;
                while(pre.right != null){
                    pre = pre.right;
                }
                pre.right = root.right;
                root.right = root.left;
                root.left = null;
                root = root.right;
            }

        }

    }
}
